package com.v1.video.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;

import com.v1.video.R;
import com.v1.video.widgets.MyDialog;

public class CustomShareSheetDialog extends MyDialog implements OnClickListener{

	/**
	 * 微信好友
	 */
	public final static int TYPE_WEIXIN = 1;
	/**
	 * QQ空间
	 */
	public final static int TYPE_QQ_SPACE = 2;
	/**
	 * 微信朋友圈
	 */
	public final static int TYPE_WEIXIN_MOMENTS = 3;
	/**
	 * 新浪微博
	 */
	public final static int TYPE_SINA_WEIBO = 4;
	/**
	 * 手机QQ
	 */
	public final static int TYPE_QQ = 5;
	/**
	 * 腾讯微博
	 */
	public final static int TYPE_TENCET_WEIBO = 6;
	
	/**
	 * 复制链接
	 */
	public final static int TYPE_COPY = 7;
	
	private HorizontalScrollView mHSView;

	private Context mCxt;
	
	private OnShareSheetItemClick mOnShareSheetItemClick;
	
	private int mSelItem = -1;
	
	public void setOnShareSheetItemClick(
			OnShareSheetItemClick onShareSheetItemClick) {
		this.mOnShareSheetItemClick = onShareSheetItemClick;
	}

	public interface OnShareSheetItemClick{
		public void onClick(int shareType);
	}
	

	public CustomShareSheetDialog(Context context) {
		super(context,R.style.dialog_headsetting);
		this.mCxt = context;

		LayoutInflater inflater=LayoutInflater.from(context);
		LinearLayout linearlayout;
		android.view.WindowManager.LayoutParams layoutparams;
		linearlayout = (LinearLayout)inflater.inflate(R.layout.custom_share_sheet_dialog, null);
//		mHSView = (HorizontalScrollView)linearlayout.findViewById(R.id.horizontalScrollView1);
		linearlayout.findViewById(R.id.tv_cancel).setOnClickListener(this);
		linearlayout.findViewById(R.id.ly_weixin).setOnClickListener(this);
		linearlayout.findViewById(R.id.ly_qq_space).setOnClickListener(this);
		linearlayout.findViewById(R.id.ly_weixin_moments).setOnClickListener(this);
		linearlayout.findViewById(R.id.ly_sina_weibo).setOnClickListener(this);
		linearlayout.findViewById(R.id.ly_qq).setOnClickListener(this);
		linearlayout.findViewById(R.id.ly_fuzhi).setOnClickListener(this);
		
		linearlayout.setMinimumWidth(10000);
		
		layoutparams = this.getWindow().getAttributes();
		layoutparams.x = 0;
		layoutparams.y = -1000;
		layoutparams.gravity = 80;//bottom
		this.onWindowAttributesChanged(layoutparams);
		
		this.setCanceledOnTouchOutside(true);		
		this.setContentView(linearlayout);
	}
	
	public CustomShareSheetDialog(Context context,int type) {
		super(context,R.style.dialog_headsetting);
		this.mCxt = context;

		LayoutInflater inflater=LayoutInflater.from(context);
		LinearLayout linearlayout;
		android.view.WindowManager.LayoutParams layoutparams;
		linearlayout = (LinearLayout)inflater.inflate(R.layout.custom_share_sheet_dialog, null);
//		mHSView = (HorizontalScrollView)linearlayout.findViewById(R.id.horizontalScrollView1);
		linearlayout.findViewById(R.id.tv_cancel).setOnClickListener(this);
		linearlayout.findViewById(R.id.ly_weixin).setOnClickListener(this);
		linearlayout.findViewById(R.id.ly_qq_space).setOnClickListener(this);
		linearlayout.findViewById(R.id.ly_weixin_moments).setOnClickListener(this);
		linearlayout.findViewById(R.id.ly_sina_weibo).setOnClickListener(this);
		linearlayout.findViewById(R.id.ly_qq).setOnClickListener(this);
		linearlayout.findViewById(R.id.ly_fuzhi).setOnClickListener(this);
		if(type == 1){
			linearlayout.findViewById(R.id.ly_fuzhi).setVisibility(View.GONE);
		}else  if(type == 2){
			linearlayout.findViewById(R.id.ly_fuzhi).setVisibility(View.GONE);
			linearlayout.findViewById(R.id.ly_sina_weibo).setVisibility(View.GONE);
			linearlayout.findViewById(R.id.ly_qq_space).setVisibility(View.GONE);
			linearlayout.findViewById(R.id.ly_qq).setVisibility(View.GONE);
		}
		linearlayout.setMinimumWidth(10000);
		
		layoutparams = this.getWindow().getAttributes();
		layoutparams.x = 0;
		layoutparams.y = -1000;
		layoutparams.gravity = 80;//bottom
		this.onWindowAttributesChanged(layoutparams);
		
		this.setCanceledOnTouchOutside(true);		
		this.setContentView(linearlayout);
	}


	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.tv_cancel:
			if (isShowing()) {
				dismiss();
			}
			return;
		case R.id.ly_weixin://微信好友
			mSelItem = TYPE_WEIXIN;
			break;
		case R.id.ly_qq_space://QQ空间
			mSelItem = TYPE_QQ_SPACE;
			break;
		case R.id.ly_weixin_moments://微信朋友圈
			mSelItem = TYPE_WEIXIN_MOMENTS;
			break;
		case R.id.ly_sina_weibo://新浪微博
			mSelItem = TYPE_SINA_WEIBO;
			break;
		case R.id.ly_qq://手机QQ
			mSelItem = TYPE_QQ;
			break;
		case R.id.ly_fuzhi://复制
			mSelItem = TYPE_COPY;
			break;
		}
		
		if(mOnShareSheetItemClick != null){
			mOnShareSheetItemClick.onClick(mSelItem);
			mSelItem = -1;
		}
		
	}
	
	@Override
	public void show() {
//		mHSView.fullScroll(View.FOCUS_LEFT);
		// TODO Auto-generated method stub
		super.show();
	}
}
